import request from "@/util/request.js";
 

/**
 * 公共接口 ，优惠券接口 , 行业此讯 , 手机号码注册
 * 
*/
//验证码
export function getYzm(key )
{
  return request.get("/api/member/randomImage/"+key,{ noAuth : true});
}
//注册
export function registerUser(obj )
{
  return request.post("/api/member/register",obj,{ noAuth : true});
}

//登陆
export function loginUser(obj )
{
  return request.post("/api/member/login",obj,{ noAuth : true});
}

//輪播圖
export function getJkSwiper( )
{
  return request.get("/api/slider/list",{ noAuth : true});
}

//輪播圖
export function getJkCompany( )
{
  return request.get("/api/company/list",{ noAuth : true});
}


//以前的=======================================
export function getmystudy( mid)
{
  return request.get("/webapi/liststudybymemberid/"+mid,{ noAuth : true});
}

export function getmyfavor( mid)
{
  return request.get("/webapi/getmyfavor/"+mid,{ noAuth : true});
}
export function getfavor(kid,mid)
{
  return request.get("/webapi/getfavor/"+kid+"/"+mid,{ noAuth : true});
}
export function listMywork(mid)
{
  return request.get("/webapi/listworksbymemberid/"+mid,{ noAuth : true});
}
export function listWorks()
{
  return request.get("/webapi/listworks",{ noAuth : true});
}
export function listEvals(mid)
{
  return request.get("/webapi/listevals/"+mid,{ noAuth : true});
}
export function getWorkById(id)
{
  return request.get("/webapi/getworkbyid/"+id,{ noAuth : true});
}
export function getAbout()
{
  return request.get("/webapi/getcompany",{ noAuth : true});
}
export function getbbslist(data)
{
  return request.get("/webapi/listBBs",data,{ noAuth : true});
}
export function addbbs(data)
{
  return request.post("/webapi/addBbs",data,{ noAuth : true});
}
export function deletebbs(ids)
{
  return request.delete("/webapi/deleteBbs/"+ids,{ noAuth : true});
}
export function addKnowledgeFavor(data)
{
  return request.post("/webapi/addknowledgefavor",data,{ noAuth : true});
}
export function getCheckinmemberbytaskid(taskid,memberid)
{
  return request.get("/webapi/getmembercheckinbytaskid/"+taskid+"/"+memberid,{ noAuth : true});
}
export function getLivelist(data)
{
  return request.get("/webapi/listlive",data,{ noAuth : true});
}
export function getKnowledgeputlist()
{
  return request.get("/webapi/listknowledgesput",{ noAuth : true});
}
export function getLivebyid(id)
{
  return request.get("/webapi/getlivebyid/"+id,{ noAuth : true});
}


export function getRealclasslist(data)
{
  return request.get("/webapi/listrealclass",data,{ noAuth : true});
}
export function getCheckinlist(data)
{
  return request.post("/webapi/listcheckin",data,{ noAuth : true});
}

export function getMylession(data)
{
  return request.post("/webapi/listmylession",data,{ noAuth : true});
}
export function addEval(data)
{
  return request.post("/webapi/addeval",data,{ noAuth : true});
}

export function addStudy(data)
{
  return request.post("/webapi/addmemberstudy",data,{ noAuth : true});
}
export function removeKnowledgeFavor(data)
{
  return request.post("/webapi/removeknowledgefavor",data,{ noAuth : true});
}
export function getKnowledgetype()
{
  return request.get("/webapi/listknowledgetype",{ noAuth : true});
}

export function valideAuth(data,mid)
{
  return request.get("/webapi/validAuth/"+mid,data,{ noAuth : true});
}


export function getAlltest()
{
  return request.get("/webapi/listtest",{ noAuth : true});
} 
export function getTestbyid(id)
{
  return request.get("/webapi/gettestbyid/"+id,{ noAuth : true});
} 
export function getKnowledgetypesMy(mid)
{
  return request.get("/webapi/listknowledgetypes/"+mid,{ noAuth : true});
}
export function getKnowledgeData(id)
{
  return request.get("/webapi/listknowledges/"+id,{ noAuth : true});
}
export function getKnowledgeById(id)
{
  return request.get("/webapi/getknowledgebyid/"+id,{ noAuth : true});
}
export function getMemberData()
{
  return request.get("/webapi/listmember",{ noAuth : true});
}
export function getMemberById(id)
{
  return request.get("/webapi/getmemberbyid/"+id,{ noAuth : true});
}
export function getUnitData()
{
  return request.get("/webapi/listfriendunit",{ noAuth : true});
}

export function getUnitById(id)
{
  return request.get("/webapi/getunitbyid/"+id,{ noAuth : true});
}

export function searchHouse(data)
{
  return request.get("/webapi/searchHouse/"+data,{ noAuth : true});
}
export function getFun(data)
{
  return request.get("/webapi/searchAction/"+data,{ noAuth : true});
}
export function getHouseData()
{
  return request.get("/webapi/listhouses",{ noAuth : true});
}
export function getHouseDataNew()
{
  return request.get("/webapi/listhousesnew",{ noAuth : true});
}
export function getHouseDataSecond()
{
  return request.get("/webapi/listhousessecond",{ noAuth : true});
}
export function getHouseById(id)
{
  return request.get("/webapi/gethousebyid/"+id,{ noAuth : true});
}
export function getFirstNews()
{
  return request.get("/webapi/listnewsfirst",{ noAuth : true});
}
export function getSwiper(pos)
{
  return request.get("/webapi/listbanner/"+pos,{ noAuth : true});
}
export function getNewstype()
{
  return request.get("/webapi/listnewstype",{ noAuth : true});
}
export function getActivitytype()
{
  return request.get("/webapi/listactivitytype",{ noAuth : true});
}
export function getNewsByTypeid(id)
{
  return request.get("/webapi/listnewsbytypeid/"+id,{ noAuth : true});
}
export function getActivityByTypeid(id)
{
  return request.get("/webapi/listactivitybytypeid/"+id,{ noAuth : true});
}
export function getActivityById(id)
{
  return request.get("/webapi/getactivitybyid/"+id,{ noAuth : true});
} 
export function getNewsById(id)
{
  return request.get("/webapi/getnewsbyid/"+id,{ noAuth : true});
} 

export function listCertByType(type)
{
  return request.get("/webapi/listcerts/"+type,{ noAuth : true});
}
export function listMyCertByType(type,phone)
{
  return request.get("/webapi/listmycerts/"+type+"/"+phone,{ noAuth : true});
}
export function listMyOnlinework(phone)
{
  return request.get("/webapi/listmyonlinework/"+phone,{ noAuth : true});
}
export function listMyMeet(phone)
{
  return request.get("/webapi/listmymeet/"+phone,{ noAuth : true});
}
export function listMyRoomall(phone)
{
  return request.get("/webapi/listmyqwdz/"+phone,{ noAuth : true});
}
export function getOnlineworkById(id)
{
  return request.get("/webapi/getonlineworkbyid/"+id,{ noAuth : true});
}
export function getRoomallById(id)
{
  return request.get("/webapi/getroomallbyid/"+id,{ noAuth : true});
}
export function getHouseMeetById(id)
{
  return request.get("/webapi/gethousemeetbyid/"+id,{ noAuth : true});
}
export function getCertById(id)
{
  return request.get("/webapi/getcertbyid/"+id,{ noAuth : true});
}
export function getJjrById(id)
{
  return request.get("/webapi/gethouseuserbyid/"+id,{ noAuth : true});
}
export function getExpertById(id)
{
  return request.get("/webapi/gethouseuserbyid/"+id,{ noAuth : true});
}
export function getHouseusers()
{
  return request.get("/webapi/listhouseusers",{ noAuth : true});
}
export function addMeet(data)
{
  return request.post("/webapi/addmeet",data,{ noAuth : true});
}
export function addRoomall(data)
{
  return request.post("/webapi/addroomall",data,{ noAuth : true});
}

export function addMemberCheckin(data)
{
  return request.post("/webapi/addmembercheckin",data,{ noAuth : true});
}

export function addMemberWork(data)
{
  return request.post("/webapi/addmemberwork",data,{ noAuth : true});
}
export function deleteMemberWork(data)
{
  return request.post("/webapi/deletememberwork",data,{ noAuth : true});
}
export function addWebcert(data)
{
  return request.post("/webapi/addcert",data,{ noAuth : true});
}

export function savenick(data)
{  
  console.log("in login data:")
  console.log(data)
  return request.post("/webapi/savenickname",data,{ noAuth : true});
}
export function login(data)
{  
  console.log("in login data:")
  console.log(data)
  return request.post("/webapi/login",data,{ noAuth : true});
}
export function validlogin(data)
{  
  console.log(data)
  return request.post("/webapi/loginvalidate",data,{ noAuth : true});
}
/**
 * ======================================================================================================
 * 处理投诉
 * 
*/
export function doprocFeed(data)
{
  return request.post("/api/program/dofeed",data,{ noAuth : true});
}
/**
 * 待处理反诉
 * 
*/
export function myfeedtodo(data)
{
  return request.post("/api/program/myfeedtodo",data,{ noAuth : true});
}
/**
 * 已处理反诉
 * 
*/
export function myfeedhasdo(data)
{
  return request.post("/api/program/myfeedhasdo",data,{ noAuth : true});
}
/**
 * 认证
 * 
*/
export function selfIdentify(data)
{
  return request.post("/api/program/identify",data,{ noAuth : true});
}
/**
 * 消息模板列表
 * 
*/
export function getTmplids(data)
{
  return request.post("/api/program/tmplids",data,{ noAuth : true});
}
/**
 * 获取主页轮播数据 无需授权
 * 
*/
export function getSwiper_()
{
  return request.post("/api/program/swiper",{},{ noAuth : true});
}
/**
 * 公告通知
 * 
*/
export function getNotice()
{
  return request.post("/api/program/notice",{},{ noAuth : true});
}
export function getNoticeitem(id)
{
  return request.get("/api/program/noticeitem?id="+id,{ noAuth : true});
}
/**
 * 首页广告弹出
 * 
*/
export function getAds()
{
  return request.post("/api/program/openads",{},{ noAuth : true});
}
/**
 * 搜索热词
 * 
*/
export function getSearchwords()
{
  return request.post("/api/program/searchwords",{},{ noAuth : true});
}
/**
 * 功能按钮
 * 
*/
export function getHomefun()
{
  return request.post("/api/program/homefun",{},{ noAuth : true});
}
export function getFungroup()
{
  return request.post("/api/program/fungroup",{},{ noAuth : true});
}

export function getFunitem(id)
{
  return request.get("/api/funById?id="+id,{ noAuth : true});
}

/**
 * @param {Object} data
 * 驾驶证
 */
export function getMycarcert(data)
{
  return request.post("/api/program/Carcert",data,{ noAuth : true});
}

export function addCarcert(data)
{
  return request.post("/api/addcarcert",data,{ noAuth : true});
}
export function editCarcert(data)
{
  return request.put("/api/editcarcert",data,{ noAuth : true});
}
/**
 * @param {Object} data
 * 机动车
 */
export function getMycars(data)
{
  return request.post("/api/program/Car",data,{ noAuth : true});
}
export function getCar(id)
{
  return request.get("/api/carById?id="+id,{ noAuth : true});
}
export function addCar(data)
{
  return request.post("/api/addcar",data,{ noAuth : true});
}
export function editCar(data)
{
  return request.put("/api/editcar",data,{ noAuth : true});
}
export function deleteCar(id)
{
  return request.delete("/api/deletecar?id="+id,{ noAuth : true});
}
/**投诉
 * @param {Object} data
 */
export function getMyfeeds(data)
{
  return request.post("/api/program/Feed",data,{ noAuth : true});
}
export function addFeed(data)
{
  return request.post("/api/addfeed",data,{ noAuth : true});
}
export function deleteFeed(id)
{
  return request.delete("/api/deleteFeed?id="+id,{ noAuth : true});
}
export function getFeed(id)
{
  return request.get("/api/feedById?id="+id,{ noAuth : true});
}
/**
 * 推广名片
 */
export function getEwmcode(data)
{
  return request.post("/front/api/program/mppic",data,{ noAuth : true});
}
/**
 * 获取手机号并更新
 */
export function updateMobile(data)
{
  return request.post("/webapi/getphonenumber",data,{ noAuth : true});
}
/**
 * 积分配置
 */
export function getSites0(title)
{
  return request.post("/api/program/caroffice",{title:title},{ noAuth : true});
}
export function getSites(data)
{
  return request.post("/api/program/acaroffice",data,{ noAuth : true});
}
export function getSitedetail(id)
{
  return request.get("/api/program/Acarofficeitem?id="+id,{ noAuth : true});
}
export function getDict(code)
{
  return request.get("/api/program/dictitem?code="+code,{ noAuth : true});
}
export function getMyscore(data)
{
  return request.post("/front/api/program/myscore",data,{ noAuth : true});
}
/**
 * 视频列表
 */
export function getVideos()
{
  return request.post("/front/api/program/video",{},{ noAuth : true});
}
export function getVideomore()
{
  return request.post("/front/api/program/videomore",{},{ noAuth : true});
}
/**
 * 答卷详情
 */
export function getInquiryDetail(data)
{
  return request.post("/front/api/program/inquiryById",data ,{ noAuth : true});
}
/**
 * 我的答卷
 */
export function getMyinquiry(data)
{
  return request.post("/front/api/program/myinquiry",data ,{ noAuth : true});
}
/**
 * 提交答卷
 */
export function submitInquiry(data)
{
  return request.post("/front/api/program/submitinquiry",
   data ,{ noAuth : true});
}
/**
 * 测试
 */
export function testArr()
{
  return request.post("/front/api/program/submitarray",
  {items:[{name:'擦擦擦',val:'111'},{name:'kkk',val:'133'}]},{ noAuth : true});
}
/**
 * 关于
 */
export function getAbout1()
{
  return request.post("/front/api/program/about",{},{ noAuth : true});
}
/**
 * @param {Object} type
 * @param {Object} id
 * 获得对象实体：JasArticle，JasArticlevideo
 * 
 */
export function getById(type,id)
{
  return request.post("/front/api/program/queryById",{type:type,id:id},{ noAuth : true});
}
/**
 * 点击次数
 */
export function clickcount(data)
{
  return request.post("/front/api/program/clickcount",data,{ noAuth : true});
}
/**
 * 文章评论列表
 */
export function getComments(data)
{
  return request.post("/front/api/program/articlecomment",data,{ noAuth : true});
}
/**
 * 我发表的评论
 */
export function getMycomments(data)
{
  return request.post("/front/api/program/myarticlecomment",data,{ noAuth : true});
}
/**
 * 我的提问
 */
export function getMyasks(data)
{
  return request.post("/front/api/program/myask",data,{ noAuth : true});
}
/**
 * 添加评论
 */
export function addComment(data)
{
  return request.post("/front/api/program/addcomment",data,{ noAuth : true});
}
/**
 * 热门推荐
 */
export function getHot()
{
  return request.post("/front/api/program/articlehot",{},{ noAuth : true});
}
/**
 * 置顶
 */
export function getTop()
{
  return request.post("/front/api/program/articletop",{},{ noAuth : true});
}

/**
	 * 获取用户信息
	 */
export function 	getUserProfile(){
		let  that = this ;//, code = this.getUserCode();
		return new Promise( (resolve,reject) => {
			uni.getUserProfile({
				lang: 'zh_CN',
				desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
				success(user) {
					//if(code) user.code = code;
					resolve({userInfo:user,islogin:false});
				},
				fail(res){
					reject(res);
				}
			});
		})
	}
	export function  getCode(provider){
		//let provider =  this.getProvider();
		return new Promise((resolve,reject)=>{
			uni.login({
				provider:provider,
				success(res) {
					//if (res.code) Cache.set(STATE_R_KEY, res.code ,10800);
					return resolve(res.code);
				},
				fail(){
					return reject(null);
				}
			})
		})
	}
	function getUserCode(){
		let isAuth =   this.isAuth(), code = '' ;
		if(isAuth)
			code =   this.getCode();
		return code;
	}
	/**
	 * 是否授权
	 */
	function isAuth(){
		let that = this;
		return new Promise((resolve,reject)=>{
			uni.getSetting({
				success(res) {
					if (!res.authSetting[that.scopeUserInfo]) {
						resolve(true)
					} else {
						resolve(true);
					}
				},
				fail(){
					 resolve(false);
				}
			});
		});
	}
	/**
	 * 获取服务供应商
	 */
	export function getProvider()
	{   
		return new Promise((resolve,reject)=>{
			uni.getProvider({
				service:'oauth',
				success(res) {
					console.log(res)
					resolve(res.provider);
				},
				fail() {
					resolve(false);
				}
			});
		});
	}
/**
 * 获取文章分类
 * 
*/
export function getArticlecolumn()
{
  return request.get("/front/api/program/column",{},{ noAuth : true});
}

export function getArticle()
{  
  return request.post("/api/program/article",{},{ noAuth : true});
}
export function getArticleitem(id)
{
  return request.get("/api/program/articleitem?id="+id,{ noAuth : true});
}

export function getInquiry()
{  
  return request.post("/front/api/program/inquiry",{},{ noAuth : true});
}

export function saveverify(data)
{  
  return request.post("/front/api/program/identify",data,{ noAuth : true});
}
export function saveCheck(data)
{  
  return request.post("/mp/program/identify",data,{ noAuth : true});
}
export function submitMyask(val)
{  
  return request.post("/front/api/program/submitask",{val:val,token:getApp().globalData.token},{ noAuth : true});
}



export function getInquiryitems(inquiryid)
{  
  return request.post("/front/api/program/inquiryitems",{"inquiryid":inquiryid},{ noAuth : true});
}
/**
 * 获取登录授权login
 * 
*/
export function getLogo()
{
  return request.get('wechat/get_logo', {}, { noAuth : true});
}


/**
 * 保存form_id
 * @param string formId 
 */
export function setFormId(formId) {
  return request.post("wechat/set_form_id", { formId: formId});
}

/**
 * 领取优惠卷
 * @param int couponId
 * 
*/
export function setCouponReceive(couponId){
  return request.post('coupon/receive', { couponId: couponId});
}
/**
 * 优惠券列表
 * @param object data
*/
export function getCoupons(data){
  return request.get('v2/coupons',data,{noAuth:true})
}

/**
 * 我的优惠券
 * @param int types 0全部  1未使用 2已使用
*/
export function getUserCoupons(types, data){
  return request.get('coupons/user/'+types, data)
}

/**
 * 首页新人优惠券
 * 
*/
export function getNewCoupon(){
  return request.get('v2/new_coupon')
}

/**
 * 文章分类列表
 * 
*/
export function getArticleCategoryList(){
  return request.get('article/category/list',{},{noAuth:true})
}

/**
 * 文章列表
 * @param int cid
 * 
*/
export function getArticleList(cid,data){
  return request.get('article/list/' + cid, data,{noAuth:true})
}

/**
 * 文章 热门列表
 * 
*/
export function getArticleHotList(){
  return request.get('article/hot/list',{},{noAuth:true});
}

/**
 * 文章 轮播列表
 * 
*/
export function getArticleBannerList(){
  return request.get('article/banner/list',{},{noAuth:true})
}

/**
 * 文章详情
 * @param int id 
 * 
*/
export function getArticleDetails(id){
  return request.get('article/details/'+id,{},{noAuth:true});
}

/**
 * 手机号+验证码登录接口
 * @param object data
*/
export function loginMobile(data){
  return request.post('login/mobile',data,{noAuth:true})
}

/**
 * 获取短信KEY
 * @param object phone
*/
export function verifyCode(){
  return request.get('verify_code', {},{noAuth:true})
}

/**
 * 验证码发送
 * @param object phone
*/
export function registerVerify(phone, reset, key, code){
  return request.post('register/verify', { phone: phone, type: reset === undefined ? 'reset' : reset, key: key, code: code },{noAuth:true})
}

/**
 * 手机号注册
 * @param object data
 * 
*/
export function phoneRegister(data){
  return request.post('register',data,{noAuth:true});
}

/**
 * 手机号修改密码
 * @param object data
 * 
*/
export function phoneRegisterReset(data){
  return request.post('register/reset',data,{noAuth:true})
}

/**
 * 手机号+密码登录
 * @param object data
 * 
*/
export function phoneLogin(data){
  return request.post('login',data,{noAuth:true})
}

/**
 * 切换H5登录
 * @param object data
*/
// #ifdef MP
export function switchH5Login(){
  return request.post('switch_h5', { 'from':'routine'});
}
// #endif

/*
 * h5切换公众号登陆
 * */
// #ifdef H5
export function switchH5Login() {
  return request.post("switch_h5", { 'from': "wechat" });
}
// #endif

/**
 * 绑定手机号
 * 
*/
export function bindingPhone(data){
  return request.post('binding',data, { noAuth : true });
}



/**
 * 绑定手机号
 * 
*/
export function bindingUserPhone(data){
  return request.post('user/binding',data);
}

/**
 * 退出登錄
 * 
*/
export function logout(){
  return request.get('logout');
}

/**
 * 获取订阅消息id
 */
export function getTemlIds()
{
  return request.get('wechat/teml_ids', {}, { noAuth:true});
}

/**
 * 首页拼团数据
 */
export function pink()
{
  return request.get('pink', {}, { noAuth:true});
}

/**
 * 获取城市信息
 */
export function getCity() {
  return request.get('city_list', { }, { noAuth: true });
}

/**
 * 获取小程序直播列表
 */
export function getLiveList(page,limit) {
  return request.get('wechat/live', { page, limit}, { noAuth: true });
}

/**
 * 获取首页DIY；
 */
export function getDiy() {
  return request.get('v2/diy/get_diy/moren', { },{ noAuth: true });
}

/**
 * 获取公众号关注
 * @returns {*}
 */
export function follow() {
  return request.get("wechat/follow", {}, { noAuth: true });
}

/**
 * 更换手机号码
 * @returns {*}
 */
export function updatePhone(data) {
  return request.post("user/updatePhone", data, { noAuth: true });
}

/**
 * 首页优惠券弹窗
 * @returns {*}
 */
export function getCouponV2() {
  return request.get("v2/get_today_coupon", {}, { noAuth: true });
}

/**
 * 新用户优惠券弹窗
 * @returns {*}
 */
export function getCouponNewUser() {
	return request.get("v2/new_coupon", {}, { noAuth: true });
}

/**
 * 首页快速选择数据
 * @param {Object} data
 */
export function category (data) {
	return request.get("category", data, { noAuth: true });
}

/**
 * 个人搜索历史
 * @param {Object} data
 */
export function searchList (data) {
	return request.get('v2/user/search_list', data, { noAuth: true });
}

/**
 * 删除搜索历史
 */
export function clearSearch () {
	return request.get('v2/user/clean_search');
}